<template>
  <div 
    class="compact-product-item"
    :class="[`size-${size}`, horizontal ? 'is-horizontal' : '']"
    @click="$emit('click', product)"
  >
    <div class="compact-product-image-container">
      <el-image 
        :src="product.image || product.coverImage" 
        :alt="product.name" 
        fit="cover"
        class="compact-product-image"
      />
      <div class="compact-tag" v-if="product.isHot || isHot">热门</div>
      <div v-if="product.distance" class="compact-distance-tag">
        <el-icon><Location /></el-icon> {{ product.distance }}km
      </div>
    </div>
    <div class="compact-product-content">
      <h4 class="compact-product-title">{{ product.name }}</h4>
      <div v-if="product.school || product.schoolName" class="compact-product-school">
        {{ product.school || product.schoolName }}
      </div>
      <div class="compact-product-footer">
        <p class="compact-product-price">¥{{ product.price }}</p>
        <el-button v-if="showButton" type="primary" size="small" round>查看</el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue';
import { Location } from '@element-plus/icons-vue';

const props = defineProps({
  product: {
    type: Object,
    required: true
  },
  size: {
    type: String,
    default: 'medium', // small, medium, large
  },
  horizontal: {
    type: Boolean,
    default: false
  },
  isHot: {
    type: Boolean,
    default: false
  },
  showButton: {
    type: Boolean,
    default: false
  }
});

defineEmits(['click']);
</script>

<style scoped>
.compact-product-item {
  background-color: #fff;
  border-radius: 10px;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.06);
  height: 100%;
  display: flex;
  flex-direction: column;
}

.compact-product-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.compact-product-image-container {
  position: relative;
  overflow: hidden;
}

.size-small .compact-product-image-container {
  height: 120px;
}

.size-medium .compact-product-image-container {
  height: 160px;
}

.size-large .compact-product-image-container {
  height: 200px;
}

.compact-product-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s;
}

.compact-product-item:hover .compact-product-image {
  transform: scale(1.1);
}

.compact-tag {
  position: absolute;
  top: 8px;
  left: 8px;
  background: linear-gradient(135deg, #ff6b6b, #ff8c8c);
  color: white;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12px;
  z-index: 1;
}

.compact-distance-tag {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.compact-product-content {
  padding: 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.compact-product-title {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 600;
  color: #333;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-product-school {
  font-size: 12px;
  color: #666;
  margin-bottom: auto;
}

.compact-product-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
}

.compact-product-price {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: #ff6b6b;
}

/* 横向布局 */
.is-horizontal {
  flex-direction: row;
}

.is-horizontal .compact-product-image-container {
  width: 100px;
  height: 100px;
}

.is-horizontal.size-small .compact-product-image-container {
  width: 80px;
  height: 80px;
}

.is-horizontal.size-medium .compact-product-image-container {
  width: 100px;
  height: 100px;
}

.is-horizontal.size-large .compact-product-image-container {
  width: 120px;
  height: 120px;
}

.is-horizontal .compact-product-content {
  flex: 1;
}

.is-horizontal .compact-product-footer {
  margin-top: auto;
}
</style> 